//
//  HHQRefreshView.swift
//  testDemo
//
//  Created by rimi on 16/10/9.
//  Copyright © 2016年 黄华强. All rights reserved.
//

import UIKit

class HHQRefreshView: UIView {

    //定义一个枚举属性来区别
    //didSet类似于oc的setter方法
    var refreshState: HHQRefreshState = .nomol {
        didSet{
            switch refreshState {
            case .nomol:
                arrowView.isHidden = false
                activityView.stopAnimating()
                titleL.text = "继续向下拉"
                UIView.animate(withDuration: 0.25, animations: {[weak self] in
                     self?.arrowView.transform = CGAffineTransform.identity
                })
               
            case .pulling:
                titleL.text = "放开就刷新"
                UIView.animate(withDuration: 0.25, animations: {[weak self] in
                    self?.arrowView.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI) - 0.00001)
                    })
                
            default:
                titleL.text = "正在刷新中"
                arrowView.isHidden = true
                activityView.startAnimating()
                
            }
        }
    }
    
    
    @IBOutlet weak var activityView: UIActivityIndicatorView!
    
    @IBOutlet weak var arrowView: UIImageView!
    @IBOutlet weak var titleL: UILabel!
    
    class func refreshV() -> HHQRefreshView {
        let xib = UINib(nibName: "HHQRefreshView", bundle: nil)
        return xib.instantiate(withOwner: nil, options: nil)[0] as! HHQRefreshView
    }
    
}
